<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>加减乘除计算</title>
		<link rel="stylesheet"href="computer.css">
	</head>
	<body>
	<p>数字1：</p>
		<input id="n1" type="text">
	<p>数字2：</p>
		<input id="n2" type="text>">
	<br>
	<br>
	<div>
		<input id="btn"  type="button"  value="求和" onclick="add()">
		<input id="btn2" type="button" value="求减" onclick="subtract()">
		<input id="btn3" type="button"value="求乘" onclick="multiply()">
		<input id="btn4" type="button" value="求除" onclick="divide()">
	</div>
	
	<p id="sum"></p>
		<script>
		function add(){
			var num1=document.getElementById('n1');
			var num2=document.getElementById('n2');
			var sum=document.getElementById('sum');
            
            var result=num1.value+num2.value;
            result=parseInt(num1.value)+parseInt(num2.value);
            result=Number(num1.value)+Number(num2.value);
            if(isNaN(num1.value)){
					alert("第一个数字不合法，是非数字型");
					
				}else if(isNaN(num2.value)){
					alert("第二个数字不合法，是非数字型");
				}else{
				sum.innerHTML=(num1.value)+"+"+(num2.value)+"="+result;
			          }
		}
		
		function subtract(){
			var num1=document.getElementById('n1');
			var num2=document.getElementById('n2');
			var sum=document.getElementById('sum');
			
			var result=num1.value-num2.value;
			result=parseInt(num1.value)-parseInt(num2.value);
            result=Number(num1.value)-Number(num2.value);
            if(isNaN(num1.value)){
					alert("第一个数字不合法，是非数字型");
					
				}else if(isNaN(num2.value)){
					alert("第二个数字不合法，是非数字型");
				}else{
				sum.innerHTML=(num1.value)+"-"+(num2.value)+"="+result;
			          }
			}
		function multiply(){
			var num1=document.getElementById('n1');
			var num2=document.getElementById('n2');
			var sum=document.getElementById('sum');
			
			var result=num1.value*num2.value;
			result=parseInt(num1.value)*parseInt(num2.value);
            result=Number(num1.value)*Number(num2.value);
            if(isNaN(num1.value)){
					alert("第一个数字不合法，是非数字型");
					
				}else if(isNaN(num2.value)){
					alert("第二个数字不合法，是非数字型");
				}else{
				sum.innerHTML=(num1.value)+"*"+(num2.value)+"="+result;
			          }
				}
		function divide(){
			var num1=document.getElementById('n1');
			var num2=document.getElementById('n2');
			var sum=document.getElementById('sum');
			
			var result=num1.value/num2.value;
			result=parseInt(num1.value)/parseInt(num2.value);
            result=Number(num1.value)/Number(num2.value);
            if(isNaN(num1.value)){
					alert("第一个数字不合法，是非数字型");
					
				}else if(isNaN(num2.value)){
					alert("第二个数字不合法，是非数字型");
				}else{
				sum.innerHTML=(num1.value)+"/"+(num2.value)+"="+result;
			          }
			
		}
		
			
		</script>
	</body>
</html>
